{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fast template matching\n", "\n", "### Background\n", "\n", "This notebook describes how the new accelerated orientation mapping facilities in Pyxem can be used.\n", "Orientation mapping with template matching is illustrated in [example 02](https://github.com/pyxem/pyxem-demos/blob/master/02%20GaAs%20Nanowire%20-%20Phase%20Mapping%20-%20Orientation%20Mapping.ipynb) but that example concerns a small dataset with the orientations very close to zone axis, which doesn't require large template libraries.\n", "In this implementation, the template library samples $SO(3)$ (all of Euler space) and subsequently compares all templates to the experimental patterns.\n", "Sampling all of Euler space requires a very large template library, on the order of 300000, in order to ensure a maximum of about 2$^\\circ$ between orientations.\n", "In the general case where we don't have any information about the orientations, this requires both a long time to calculate the template library and to index the dataset.\n", "\n", "The \"fast\" approach aims to mimic ideas in commercial template matching codes like ASTAR. \n", "The goal here is that real 4D-STEM datasets containing arbitrary orientations can be indexed in reasonable time.\n", "To achieve this, template libraries are simulated by sampling $S^2$ (the surface of the sphere) instead, which represents all possible beam directions relative to the crystal.\n", "The euler angle that represents the in-plane rotation is constrained to 0.\n", "Removing one degree of freedom drastically limits the size of the library.\n", "The in-plane rotation angle is found during the indexation process by matching the templates to the images in polar coordinates.\n", "This is also a computationally demanding task but it can be substantially parallelized.\n", "**If you have large 4D-STEM/NBED dataset of real samples with unknown orientations you should consider following this example**.\n", "\n", "### Structure\n", "\n", "1. Load, inspect, calibrate data\n", "2. Preprocess images\n", "3. Build template library\n", "4. Perform indexation\n", " * One pattern, one template\n", " * One pattern, many templates\n", " * Many patterns, many templates" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import hyperspy.api as hs\n", "import zarr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Load, inspect, calibrate data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# how to save using the zip store with zarr (good for sharing datasets with 1 file)\n", "#filename = 'data/11/sample_with_g.zspy'\n", "#store = zarr.ZipStore(path=filename)\n", "#experimental_data.save(store,close_file=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:silx.opencl.common:Unable to import pyOpenCl. Please install it from: https://pypi.org/project/pyopencl\n" ] } ], "source": [ "filename = 'data/11/sample_with_g.zspy'\n", "store = zarr.ZipStore(path=filename)\n", "experimental_data = hs.load(store, lazy=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n",
"
| \n",
" \n",
"
| \n",
"